#ifndef WAVEWATER_H
#define WAVEWATER_H

#include <QWidget>
#include <QMap>
#include <QtUiPlugin/QDesignerExportWidget>
#include "QPushButton"
#include "QFileDialog"
#include "qdebug.h"
#include "qgridlayout.h"
#include "QLabel"

class WaveWater : public QWidget
{
    Q_OBJECT

    Q_PROPERTY(int damping READ getDamping WRITE setDamping)
    Q_PROPERTY(int refractive READ getRefractive WRITE setRefractive )
    Q_PROPERTY(int  stoneSize READ getStoneSize WRITE setStoneSize )
    Q_PROPERTY(int stoneWeight READ getStoneWeight WRITE setStoneWeight )
    Q_PROPERTY(QPixmap image READ getImage WRITE setImage )

public:
    explicit WaveWater(QWidget *parent = 0);
    ~WaveWater();

protected:
    void mousePressEvent(QMouseEvent *);
    void paintEvent(QPaintEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);\

private:
    int damping;//波能衰减系数
    int refractive;//波能折射系数
    int stoneSize;//石头大小
    int stoneWeight;//石头重量
    QPixmap image;//渲染图片

    QImage imageRender;//渲染像素图片
    QImage imageOrigin;//渲染源
    QPixmap pixmap;//渲染图片

    int imageWidth;
    int imageHeight;
    int** waveBuffer1;//波能缓冲区1
    int** waveBuffer2;//波能缓冲区2

    bool isStopped;//水波是否结束波动
    bool isPressed;//鼠标是否按下
    QPoint lastPoint;//鼠标按下坐标
    QTimer* timer;//定时器

    QString filename;
    QPushButton* selectFileBtn;
    QLabel* label;
    QWidget* mainwidget;

private slots:
    //执行计算位图进行绘制
    void drawImage();
    //水波扩散
    void wavaSpread();
    //渲染水波位图
    void waveRender();
    //扔石子
    void dropStone(int x,int y,int stoneSize,int stoneWeight);

    //
    void btn_selected();

public:
    int getDamping() const;
    int getRefractive() const;
    int getStoneSize() const;
    int getStoneWeight() const;

    QPixmap getImage() const;

    QSize sizeHint() const;
    QSize minimumSizeHint() const;

public Q_SLOTS:
    void setDamping(int damping);
    void setRefractive(int refractiva);
    void setStoneSize(int stoneSize);
    void setStoneWeight(int stoneWeight);
    void setImage(const QPixmap image);

};

#endif
